package tech.aistar.day03;

import tech.aistar.util.DateUtil;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;


/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/7/20 9:57 上午
 */
public class PrintCalendarDemo {
    public static void main(String[] args) {
        //int nextInt();//整数 - java.util.InputMismatchException 输入的不是一个数字的话
        //double nextDouble();//小数
        //String nextLine();//字符串

        //细节:如果一旦在nextLine之前调用nextInt/nextDouble,导致nextLine失效.
        Scanner sc = new Scanner(System.in);
        System.out.print("input year>");
        int year = sc.nextInt();

        System.out.print("input month>");
        int month = sc.nextInt();

        print(year,month);

    }

    /**
     *              2022年7月
     *  日   一   二   三   四   五   六
     *                         1    2
     *
     *                         20*
     *                        最大天数
     * @param year
     * @param month
     */
    private static void print(int year, int month) {
        System.out.printf("\t\t%d年%d月\n",year,month);
        System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\n","日","一","二","三","四","五","六");

        //1. 某年某月的1号是周几
        int week = DateUtil.getDayOfWeek(year,month,1);

        //2. 某年某月的最大天数
        int max = DateUtil.getMaxDays(year,month);

        //3. 今天是几号
        int date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        int count = 0;

        //4. 打印
        for (int i = 0; i < week; i++) {
            System.out.print("\t");
            count++;
        }

        for (int i = 1; i <= max ; i++) {
            System.out.print(i==date?(i+"*\t"):(i+"\t"));
            if(++count==7){
                System.out.println();
                count = 0;
            }
        }
    }
}
